//
//  RobCell.m
//  MyTrip
//
//  Created by zhang on 15/8/22.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "RobCell.h"
#import "RobCollectionCell.h"

@interface RobCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@end


@implementation RobCell

- (void)dealloc
{
    [_robCollectionArray release];
    [_robCollection release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(365 / 2 * OffWidth, 180 * OffHeight);
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing = 0;
        self.robCollection = [[[UICollectionView alloc] initWithFrame:CGRectMake(5 * OffWidth, 0, (375 - 10) * OffWidth, 360 * OffHeight) collectionViewLayout:layout] autorelease];
        [_robCollection setBackgroundColor:[UIColor whiteColor]];
        _robCollection.delegate  = self;
        _robCollection.dataSource = self;
        [_robCollection registerClass:[RobCollectionCell class] forCellWithReuseIdentifier:@"robcell"];
        [self.contentView addSubview:_robCollection];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return [_robCollectionArray count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    RobCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"robcell" forIndexPath:indexPath];
    NSDictionary *dic = [_robCollectionArray objectAtIndex:indexPath.item];
    [cell cellSetValueWithDic:dic];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = [_robCollectionArray objectAtIndex:indexPath.item];
    NSNumber *idNum = [dic objectForKey:@"id"];
    [self.delegate clickIndex:indexPath WithidNum:idNum];

}









- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
